package com.dwxt.mall.controller;

import com.dwxt.common.annotation.ValidateFiled;
import com.dwxt.common.annotation.ValidateGroup;
import com.dwxt.common.base.BaseResult;
import com.dwxt.mall.entity.Product;
import com.dwxt.mall.entity.TrainHall;
import com.dwxt.mall.service.TrainHallService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/mall/hall")
@RestController
public class TrainHallController {

    @Autowired
    private TrainHallService trainHallService;

    /**
     * showdoc
     *
     * @param pageNum   必选 int 页码（1开始)
     * @param pageSize  必选 int 每页数量
     * @param longitude 必选 string 经度
     * @param latitude  必选 string 纬度
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":8,"address":"九龙坡袁家岗","name":"燕龙的座球场","distance":"距离轻轨站200米","phone":"15123058498","password":"E10ADC3949BA59ABBE56E057F20F883E","weekStart":"周一","weekEnd":"周五","dayStart":"09:00","dayEnd":"18:00","isEffective":1,"createTime":"2020-04-02T15:53:01.000+0000","priority":200,"coverImgUrl":"http://demo.com","carouselImgUrl":"http://demo2.com","latitude":"29.555803","longitude":"106.521961","desp":null,"meter":126.20870910573923}],"pageNum":1,"pageSize":1,"size":1,"startRow":0,"endRow":0,"pages":1,"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1}}
     * @catalog 商城/培训馆
     * @title 培训馆分页查询
     * @description 培训馆分页查询
     * @url /mall/hall/selectHallPage
     */
    @RequestMapping("/selectHallPage")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, notNull = true),
            @ValidateFiled(index = 1, notNull = true),
            @ValidateFiled(index = 2, filedName = "longitude", notNull = true),
            @ValidateFiled(index = 2, filedName = "latitude", notNull = true),
    })
    public BaseResult selectHallPage(Integer pageNum, Integer pageSize, TrainHall hall) {
        PageHelper.startPage(pageNum, pageSize);
        return trainHallService.selectHallList(hall);
    }

    /**
     * showdoc
     *
     * @param id 必选 int 培训馆id
     * @return {"status":200,"msg":"SUCCESS","data":[{"id":6,"name":"优惠券","price":10.0,"integral":0,"stock":10,"desp":null,"module":"卡券礼包","categoryId":4,"type":"轮播图","isShelf":1,"createTime":"2020-04-09T10:51:37.000+0000","supplierId":11,"payCategory":2,"version":0,"limitNumber":1,"isLimit":1,"priority":10,"deliveryMethod":"商家配送","coverImgUrl":"http://localhost:2011/upload/20200409105103055.png","carouselImgUrl":"http://localhost:2011/upload/20200409105115473.png,http://localhost:2011/upload/20200409105119356.png"}]}
     * @catalog 商城/培训馆
     * @title 查询培训馆券码
     * @description 查询培训馆券码
     * @url /mall/hall/selectById
     */
    @RequestMapping("/selectById")
    public BaseResult selectById(Integer id) {
        List<Product> product = trainHallService.selectProductById(id);
        return BaseResult.ok(product);
    }
}
